﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using BasicCMS.Core.Services;
using BasicCMS.Core.ViewModels;

namespace BasicCMS.Core.Controllers
{
    public class AccountController : Controller
    {
        private readonly IAccountService accountService;
        public AccountController(IAccountService accountService)
        {
            this.accountService = accountService;
        }

        [HttpGet]
        public ActionResult LogOn()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Logon(LogOnViewModel model)
        {
            CheckAccountResult result=accountService.CheckAccount(model.LoginName, model.Password);
            if (result==CheckAccountResult.Success)
            {
                Session["UserName"] = model.LoginName;
                return RedirectToAction("Index", "Admin");
            }
            else if (result == CheckAccountResult.LoginNameNotExist)
            {
                ViewData["Message"] = "登陆用户不存在!";
            }
            else if (result == CheckAccountResult.PasswordNotExist)
            {
                ViewData["Message"] = "密码错误!";
            }
            return View();
        }
    }
}
